/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 cheats.cpp

	$Header: /game/cheats.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "cheats.h"

#include "adventure_frame.h"
#include "adventure_map.h"
#include "bound_handler.h"
#include "external_string.h"
#include "mouse_event.h"
#include "resource.h"
#include "simple_dialog.h"
#include "standard_fonts.h"
#include "string_insensitive_compare.h"
#include "text_edit_window.h"


namespace
{
	/*
	** Cheat strings
	*/
	t_external_string const k_text_free_materials(			"free_materials.cheats");
	t_external_string const k_text_auto_play(				"auto_play.cheats");
	t_external_string const k_text_win_combat(				"win_combat.cheats");
	t_external_string const k_text_lose_combat(				"lose_combat.cheats");
	t_external_string const k_text_elven_chainmail(			"elven_chainmail.cheats");
	t_external_string const k_text_dagger_of_despair(		"dagger_of_despair.cheats");
	t_external_string const k_text_sword_of_the_gods(		"sword_of_the_gods.cheats");	  
	t_external_string const k_text_ring_of_greater_negation("ring_of_greater_negation.cheats");	
	t_external_string const k_text_crusaders(				"crusaders.cheats");	
	t_external_string const k_text_champions(				"champions.cheats");	
	t_external_string const k_text_minotaur(				"minotaur.cheats");	
	t_external_string const k_text_angels(					"angels.cheats");	
	t_external_string const k_text_dwarves(					"dwarves.cheats");	
	t_external_string const k_text_magi(					"magi.cheats");	
	t_external_string const k_text_titans(					"titans.cheats");	
	t_external_string const k_text_vampires(				"vampires.cheats");	
	t_external_string const k_text_devils(					"devils.cheats");	
	t_external_string const k_text_trolls(					"trolls.cheats");	
	t_external_string const k_text_nightmares(				"nightmares.cheats");	
	t_external_string const k_text_black_dragons(			"black_dragons.cheats");	
	t_external_string const k_text_sprites(					"sprites.cheats");	
	t_external_string const k_text_wolves(					"wolves.cheats");	
	t_external_string const k_text_elves(					"elves.cheats");	
	t_external_string const k_text_unicorn(					"unicorn.cheats");	
	t_external_string const k_text_phoenix(					"phoenix.cheats");	
	t_external_string const k_text_ogre_magi(				"ogre_magi.cheats");	
	t_external_string const k_text_behemoth(				"behemoth.cheats");	
	t_external_string const k_text_sea_monster(				"sea_monster.cheats");	
	t_external_string const k_text_shroud_fow(				"shroud_fow.cheats");	
	t_external_string const k_text_gain_skill(				"gain_skill.cheats");	
	t_external_string const k_text_increase_level(			"increase_level.cheats");	
	t_external_string const k_text_learn_spells(			"learn_spells.cheats");	
	t_external_string const k_text_lose_scenario(			"lose_scenario.cheats");	
	t_external_string const k_text_unlimited_movement(		"unlimited_movement.cheats");	
	t_external_string const k_text_win_scenario(			"win_scenario.cheats");	
	t_external_string const k_text_max_luck(				"max_luck.cheats");	
	t_external_string const k_text_max_morale(				"max_morale.cheats");	
	t_external_string const k_text_reveal_puzzle_map(		"reveal_puzzle_map.cheats");	
	t_external_string const k_text_tattooed_white_trash(	"tatooed_white_trash.cheats");	
	t_external_string const k_text_build_all_buildings(		"build_all_buildings.cheats");	
	t_external_string const k_text_access_cheat_menu(		"access_cheat_menu.cheats");	
	t_external_string const k_text_jack_cheat(				"old_man_jack.cheats" );
}


// ------------------------------------------------------------------
// ------------------------------------------------------------------
t_dialog_cheat::t_dialog_cheat( t_window* parent, t_adventure_map * map ) :
								t_window( k_completely_transparent, parent ),
								m_frame( parent ), m_map( map )
{
	t_screen_rect  rect;
	t_screen_point point;

	// create edit box
	t_text_edit_handler handler;

	if( !parent )
		parent = t_window::get_main_window();

	rect = t_window::get_main_window()->get_screen_rect();

	point.x = ( rect.width() / 2 );
	point.y = ( rect.height() / 2 );

	rect.top = point.y - 25;
	rect.bottom = point.y + 25;
	rect.left = point.x - 150;
	rect.right = point.x + 150;

	init( rect );

	m_cheat_box = new t_text_edit_window( get_font( 30 ), rect, parent, "", t_pixel_24(140,245,175) );
	m_cheat_box->set_drop_shadow( true, t_pixel_24(0,0,0));
	handler = bound_handler( *this, &t_dialog_cheat::cheat_input_change );
	m_cheat_box->set_change_handler( handler );
	handler = bound_handler( *this, &t_dialog_cheat::cheat_input_finished );
	m_cheat_box->set_end_edit_handler( handler );
	m_cheat_box->set_center_horizontal();
	m_cheat_box->set_center_vertical();
	m_cheat_box->begin_edit();	// force a string edit
}

// ------------------------------------------------------------------
// respond to a change in the edit box
// ------------------------------------------------------------------
void t_dialog_cheat::cheat_input_change( t_text_edit_window* )
{
}

// ------------------------------------------------------------------
// respond to a change in the edit box
// ------------------------------------------------------------------
void t_dialog_cheat::cheat_input_finished( t_text_edit_window* )
{
	std::string text = m_cheat_box->get_text();

	// clean up 
	m_cheat_box->close();
	m_cheat_box = 0;
	close();

	if( !m_frame )
		return;

	/*
	** evaluate the cheat string
	*/

	if( !string_insensitive_compare( text, k_text_free_materials ) )	
	{
		do_cheat( k_id_cheat_materials );
	} else
	if( !string_insensitive_compare( text, k_text_auto_play ) )				
	{
		do_cheat( k_id_cheat_toggle_auto_play );
	} else
	if( !string_insensitive_compare( text, k_text_win_combat ) )				
	{
		do_cheat( k_id_cheat_win_combat );
	} else
	if( !string_insensitive_compare( text, k_text_lose_combat ) )				
	{
		do_cheat( k_id_cheat_lose_combat );
	} else
	if( !string_insensitive_compare( text, k_text_elven_chainmail ) )			
	{
		do_cheat( k_id_cheat_create_elven_chainmail );
	} else
	if( !string_insensitive_compare( text, k_text_dagger_of_despair ) )		
	{
		do_cheat( k_id_cheat_create_dagger_of_despair );
	} else
	if( !string_insensitive_compare( text, k_text_sword_of_the_gods ) )		
	{
		do_cheat( k_id_cheat_create_sword_of_the_gods );
	} else
	if( !string_insensitive_compare( text, k_text_ring_of_greater_negation ) )
	{
		do_cheat( k_id_cheat_create_greater_ring_of_vulnerability );
	} else
	if( !string_insensitive_compare( text, k_text_crusaders ) )				
	{
		do_cheat( k_id_cheat_create_crusaders );
	} else
	if( !string_insensitive_compare( text, k_text_champions ) )				
	{
		do_cheat( k_id_cheat_create_champions );
	} else
	if( !string_insensitive_compare( text, k_text_angels ) )					
	{
		do_cheat( k_id_cheat_create_angels );
	} else
	if( !string_insensitive_compare( text, k_text_dwarves ) )					
	{
		do_cheat( k_id_cheat_create_dwarves );
	} else
	if( !string_insensitive_compare( text, k_text_minotaur ) )				
	{
		do_cheat( k_id_cheat_create_minotaurs );
	} else
	if( !string_insensitive_compare( text, k_text_magi ) )					
	{
		do_cheat( k_id_cheat_create_magi );
	} else
	if( !string_insensitive_compare( text, k_text_titans ) )					
	{
		do_cheat( k_id_cheat_create_titans );
	} else
	if( !string_insensitive_compare( text, k_text_vampires ) )				
	{
		do_cheat( k_id_cheat_create_vampires );
	} else
	if( !string_insensitive_compare( text, k_text_devils ) )					
	{
		do_cheat( k_id_cheat_create_devils );
	} else
	if( !string_insensitive_compare( text, k_text_trolls ) )					
	{
		do_cheat( k_id_cheat_create_trolls );
	} else
	if( !string_insensitive_compare( text, k_text_nightmares ) )				
	{
		do_cheat( k_id_cheat_create_nightmares );
	} else
	if( !string_insensitive_compare( text, k_text_black_dragons ) )			
	{
		do_cheat( k_id_cheat_create_black_dragons );
	} else
	if( !string_insensitive_compare( text, k_text_sprites ) )					
	{
		do_cheat( k_id_cheat_create_sprites );
	} else
	if( !string_insensitive_compare( text, k_text_wolves ) )					
	{
		do_cheat( k_id_cheat_create_wolves );
	} else
	if( !string_insensitive_compare( text, k_text_elves ) )					
	{
		do_cheat( k_id_cheat_create_elves );
	} else
	if( !string_insensitive_compare( text, k_text_unicorn ) )					
	{
		do_cheat( k_id_cheat_create_unicorns );
	} else
	if( !string_insensitive_compare( text, k_text_phoenix ) )					
	{
		do_cheat( k_id_cheat_create_phoenixes );
	} else
	if( !string_insensitive_compare( text, k_text_ogre_magi ) )				
	{
		do_cheat( k_id_cheat_create_ogre_magi );
	} else
	if( !string_insensitive_compare( text, k_text_behemoth ) )				
	{
		do_cheat( k_id_cheat_create_behemoths );
	} else
	if( !string_insensitive_compare( text, k_text_sea_monster ) )				
	{
		do_cheat( k_id_cheat_create_sea_monsters );
	} else
	if( !string_insensitive_compare( text, k_text_shroud_fow ) )				
	{
		do_cheat( k_id_cheat_toggle_shroud_fow );
	} else
	if( !string_insensitive_compare( text, k_text_gain_skill ) )				
	{
		do_cheat( k_id_cheat_gain_skill );
	} else
	if( !string_insensitive_compare( text, k_text_increase_level ) )			
	{
		do_cheat( k_id_cheat_increase_level );
	} else
	if( !string_insensitive_compare( text, k_text_learn_spells ) )			
	{
		do_cheat( k_id_cheat_learn_spells );
	} else
	if( !string_insensitive_compare( text, k_text_lose_scenario ) )			
	{
		do_cheat( k_id_cheat_lose_map );
	} else
	if( !string_insensitive_compare( text, k_text_unlimited_movement ) )		
	{
		do_cheat( k_id_cheat_unlimited_move );
	} else
	if( !string_insensitive_compare( text, k_text_win_scenario ) )			
	{
		do_cheat( k_id_cheat_win_map );
	} else
	if( !string_insensitive_compare( text, k_text_max_luck ) )				
	{
		do_cheat( k_id_cheat_maximum_luck );
	} else
	if( !string_insensitive_compare( text, k_text_max_morale ) )				
	{
		do_cheat( k_id_cheat_maximum_morale );
	} else
	if( !string_insensitive_compare( text, k_text_reveal_puzzle_map ) )		
	{
		do_cheat( k_id_cheat_reveal_puzzle );
	} else
	if( !string_insensitive_compare( text, k_text_tattooed_white_trash ) )	
	{
		do_cheat( k_id_cheat_tattooed_white_trash );
	} else
	if( !string_insensitive_compare( text, k_text_build_all_buildings ) )		
	{
		do_cheat( k_id_cheat_build_all_buildings );
	} else
	if( !string_insensitive_compare( text, k_text_access_cheat_menu ) )		
	{
		do_cheat( k_id_cheat_developer_cheat_menu );
	}
	if ( string_insensitive_compare( text, k_text_jack_cheat ) == 0)
		do_cheat( k_id_cheat_old_man_jack );
}

// ------------------------------------------------------------------
// do the cheat and set up the player as a cheater
// ------------------------------------------------------------------
void t_dialog_cheat::do_cheat( int cheat_id )
{
	m_map->set_cheater();
	m_frame->menu_click( cheat_id );
}
